package louie.wendy.redisrepository.service.impl;

import louie.wendy.redisrepository.entity.User;
import louie.wendy.redisrepository.repository.UserRepository;
import louie.wendy.redisrepository.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @author louie
 */
@Service
public class UserServiceImpl implements UserService {
    private final UserRepository userRepository;

    public UserServiceImpl (UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public User save(User user) {
        return userRepository.save(user);
    }

    @Override
    public User findUser(String userId) {
        return userRepository.findById(userId).orElse(null);
    }

    @Override
    public void delete(String userId) {
        userRepository.deleteById(userId);
    }

    @Override
    public void update(User user) {
        userRepository.save(user);
    }
}
